package mysql.v1;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Collection;

/**
 *
 */
public class MysqlJDBCV1 {
    public  static  void  main(String[]args){
        //1.注册Mysql驱动
        Class.forName("com.mysql.jdbc.Driver");
        //2.准备SQL
        String username="root";
        String password="";
        String url="jdbc:mysql://127.0.0.1:3309/mi?characterEncoding=UTF-8";
        //连接成功Msql sql工具类
        Collection con=
        DriverManager.getConnection(url,username,password);
        System.out.println("测试Java连接数据库对象:"+con);
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery();
        st.executeQuery(sql);
        System.out.println("----查询book表结果如下----");
        while (rs.nex()){
            int id=rs.getInt("id");
            String autor=rs.getString("autor");
            String name=rs.getString("name");
            int price=rs.getString("price");
            String date=rs.getString("date");
            int number=rs.getString("number");
            String discount=rs.getString("discount");
            System.out.println("作者"+author+"打折情况");

        }
    }
}
